import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class FrontDeskTest {
    private FrontDesk frontDesk;
    private Movie testMovie;
    private Screening testScreening;
    private Seat testSeat;
    @BeforeEach
    void setUp() {
        // 初始化 FrontDesk 对象，
        frontDesk = new FrontDesk("front001", "frontName", "frontPass", new Date(), "1234567890");
        // 初始化测试电影
        testMovie = new Movie("movie001", "Test Movie", "Test Director", "Test Actors","Test Intro",100,7.5);
        // 初始化测试放映场次
        testScreening = new Screening("screen001", testMovie, "1号厅",new Date(),50);
        // 初始化测试座位
        testSeat = new Seat(1, 2);
    }
    // 测试添加放映场次方法
    @Test
    void testAddScreening() {
        int beforeSize = frontDesk.getScreenings().size();
        frontDesk.addScreening(testScreening);
        assertEquals(beforeSize + 1, frontDesk.getScreenings().size());
    }
    // 测试添加电影方法
    @Test
    void testAddMovie() {
        int beforeSize = frontDesk.getMovies().size();
        frontDesk.addMovie(testMovie);
        assertEquals(beforeSize + 1, frontDesk.getMovies().size());
    }
    // 测试根据范围列出放映场次方法
    @Test
    void testListScreenings() {
        frontDesk.addScreening(testScreening);
        List<Screening> screenings = frontDesk.listScreenings("today");
        assertFalse(screenings.isEmpty());
    }
    // 测试根据电影标题查询放映场次方法
    @Test
    void testQueryMovieScreeningsByTitle() {
        frontDesk.addScreening(testScreening);
        Screening result = frontDesk.queryMovieScreeningsByTitle("Test Movie");
        assertEquals(testScreening, result);
    }
    // 测试添加票方法
    @Test
    void testAddTicket() {
        Ticket ticket = new Ticket("TICKET-123", testScreening, new ArrayList<>(),0,new Date(),0,0.0,0,0.0);
        frontDesk.addTicket(ticket);
        assertTrue(frontDesk.getActiveTickets().contains(ticket));
        // 测试重复添加
        frontDesk.addTicket(ticket);
        // 可结合输出断言控制台提示“票号已存在”，或检查 activeTickets 大小未变
        assertEquals(1, frontDesk.getActiveTickets().size());
    }
    // 测试退票方法
    @Test
    void testRefundTicket() {
        Ticket ticket = new Ticket("TICKET-123", testScreening, new ArrayList<>(),0,new Date(),0,0.0,0,0.0);
        frontDesk.addTicket(ticket);
        assertTrue(frontDesk.refundTicket(ticket, 100.0));
        assertTrue(frontDesk.getRefundedTickets().contains(ticket));
        assertFalse(frontDesk.getActiveTickets().contains(ticket));
    }
    // 测试根据票号查找票方法
    @Test
    void testFindTicketById() {
        Ticket ticket = new Ticket("TICKET-123", testScreening, new ArrayList<>(),0,new Date(),0,0.0,0,0.0);
        frontDesk.addTicket(ticket);
        Ticket result = frontDesk.findTicketById("TICKET-123");
        assertEquals(ticket, result);
        // 测试忽略大小写、空格匹配
        Ticket resultIgnoreCase = frontDesk.findTicketById("ticket-123");
        assertEquals(ticket, resultIgnoreCase);
        Ticket resultTrim = frontDesk.findTicketById("  TICKET-123  ");
        assertEquals(ticket, resultTrim);
    }
    // 测试登录、登出、密码管理方法
    @Test
    void testLoginLogoutManagePassword() {
        frontDesk.login();
        frontDesk.logout();
        frontDesk.managePassword();
    }
}

